prefix api

This commit is contained in:
cupcakearmy 2021-05-02 14:02:40 +02:00
parent ab0166c5ac
commit c869238171
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9
4 changed files with 18 additions and 9 deletions

View File

@ -14,7 +14,7 @@ export type NotePublic = Pick<Note, 'contents'>
export async function create(note: Note) { export async function create(note: Note) {
const { data } = await base({ const { data } = await base({
url: '/notes/', url: '/api/notes',
method: 'post', method: 'post',
data: note, data: note,
}) })
@ -23,7 +23,7 @@ export async function create(note: Note) {
export async function get(id: string) { export async function get(id: string) {
const { data } = await base({ const { data } = await base({
url: `/notes/${id}`, url: `/api/notes/${id}`,
method: 'delete', method: 'delete',
}) })
return data as NotePublic return data as NotePublic
@ -31,7 +31,7 @@ export async function get(id: string) {
export async function info(id: string) { export async function info(id: string) {
const { data } = await base({ const { data } = await base({
url: `/notes/${id}`, url: `/api/notes/${id}`,
method: 'get', method: 'get',
}) })
return data as NoteInfo return data as NoteInfo

View File

@ -9,7 +9,7 @@
import TextInput from '$lib/ui/TextInput.svelte' import TextInput from '$lib/ui/TextInput.svelte'
let note: Note = { let note: Note = {
contents: 'secret', contents: '',
password: false, password: false,
views: 1, views: 1,
expiration: 60, expiration: 60,
@ -74,7 +74,7 @@
{:else} {:else}
<form on:submit|preventDefault={submit}> <form on:submit|preventDefault={submit}>
<fieldset disabled={loading}> <fieldset disabled={loading}>
<TextArea label="note" bind:value={note.contents} /> <TextArea label="note" bind:value={note.contents} placeholder="..." />
<div class="bottom"> <div class="bottom">
<Switch label="advanced" bind:value={advanced} /> <Switch label="advanced" bind:value={advanced} />

View File

@ -1,3 +1,6 @@
# DEV Compose file.
# For a production file see: ...
version: '3.7' version: '3.7'
services: services:

View File

@ -36,7 +36,7 @@ struct CreateResponse {
id: String, id: String,
} }
#[post("/notes/")] #[post("/notes")]
async fn create(note: web::Json<Note>) -> impl Responder { async fn create(note: web::Json<Note>) -> impl Responder {
let mut n = note.into_inner(); let mut n = note.into_inner();
let id = generate_id(); let id = generate_id();
@ -105,7 +105,13 @@ async fn delete(path: web::Path<NotePath>) -> impl Responder {
} }
pub fn init(cfg: &mut web::ServiceConfig) { pub fn init(cfg: &mut web::ServiceConfig) {
cfg.service(create); cfg.service(
cfg.service(delete); web::scope("/api")
cfg.service(one); .service(create)
.service(delete)
.service(one),
);
// cfg.service(create);
// cfg.service(delete);
// cfg.service(one);
} }